setwd("~/Desktop/Replication Archive")

#####STUDY 1#####
study1 <- read.csv("study1.csv", stringsAsFactors=FALSE)

####TREATMENTS####
###FAVOR CHANGE IS ALWAYS = 2 AND OPPOSE CHANGE IS ALWAYS = 1
##COLLECTIVE BARGAINING
#STATE
study1$CB_ST_SQ <- NA
study1$CB_ST_SQ[study1$Q76 == 2] <- 1
study1$CB_ST_SQ[study1$Q76 == 1] <- 0
study1$CB_ST_SQ[study1$Q82 == 2] <- 1
study1$CB_ST_SQ[study1$Q82 == 1] <- 0
study1$CB_ST_TREAT <- as.numeric(!is.na(study1$Q82))

#FED
study1$CB_FED_SQ <- NA
study1$CB_FED_SQ[study1$Q42 == 2] <- 1
study1$CB_FED_SQ[study1$Q42 == 1] <- 0
study1$CB_FED_SQ[study1$Q44.1 == 2] <- 1
study1$CB_FED_SQ[study1$Q44.1 == 1] <- 0
study1$CB_FED_TREAT <- as.numeric(!is.na(study1$Q44.1))

##2/3 MAJORITY
#STATE
study1$MAJ_ST_SQ <- NA
study1$MAJ_ST_SQ[study1$Q78 == 2] <- 1
study1$MAJ_ST_SQ[study1$Q78 == 1] <- 0
study1$MAJ_ST_SQ[study1$Q84 == 2] <- 1
study1$MAJ_ST_SQ[study1$Q84 == 1] <- 0
study1$MAJ_ST_TREAT <- as.numeric(!is.na(study1$Q84))

#FED
study1$MAJ_FED_SQ <- NA
study1$MAJ_FED_SQ[study1$Q43 == 2] <- 1
study1$MAJ_FED_SQ[study1$Q43 == 1] <- 0
study1$MAJ_FED_SQ[study1$Q43.1 == 2] <- 1
study1$MAJ_FED_SQ[study1$Q43.1 == 1] <- 0
study1$MAJ_FED_TREAT <- as.numeric(!is.na(study1$Q43.1))
##################

####CREATE / RENAME VARIABLES####
study1$MALE <- as.numeric(study1$Q68.1 == 1)
study1$AGE <- study1$Q40_1
study1$AGE[study1$AGE==0] <- NA
study1$AGE[study1$AGE==220] <- 22
study1$EDUCATION <- study1$Q60
study1$INCOME <- study1$Q48.2
study1$LIBCON <- study1$Q52 #LIBERAL TO CONSERVATIVE
study1$RISK <- abs(11-study1$Q77) #RISK AVERSION RESCALED SO THAT HIGHER VALUES MEAN MORE RISK AVERSE
study1$UNIONS <- study1$Q41_3 #FEELING THERMOMETER TOWARDS UNIONS
study1$TAXES <- study1$Q84_1 #FAVOR LOWERING THE BUDGET DEFICIT BY RAISING TAXES
study1$WORKS <- abs(5 - study1$Q7_1) + (study1$Q7_2 - 1) + abs(5 - study1$Q7_3) + (study1$Q7_4 - 1) + (study1$Q7_5 - 1) #CONSTITUTION STILL WORKS
study1$BLACK <- as.numeric(study1$Q56.2 == 2)
study1$HISP <-  as.numeric(study1$Q56.2 == 3)
study1$WHITE <-  as.numeric(study1$Q56.2 == 5)
########################

#####STUDY 1 FOLLOWUP #####
study1_fu <- read.csv("study1_followup.csv", stringsAsFactors=FALSE)

####TREATMENTS####
###FAVOR CHANGE IS ALWAYS = 2 AND OPPOSE CHANGE IS ALWAYS = 1
##COLLECTIVE BARGAINING
study1_fu$CB_SQ <- NA
study1_fu$CB_SQ[study1_fu$Q97 == 2] <- 1
study1_fu$CB_SQ[study1_fu$Q97 == 1] <- 0
study1_fu$CB_SQ[study1_fu$Q99 == 2] <- 1
study1_fu$CB_SQ[study1_fu$Q99 == 1] <- 0
study1_fu$CB_SQ[study1_fu$Q101 == 2] <- 1
study1_fu$CB_SQ[study1_fu$Q101 == 1] <- 0
study1_fu$CB_SQ[study1_fu$Q103 == 2] <- 1
study1_fu$CB_SQ[study1_fu$Q103 == 1] <- 0

study1_fu$CB_TREAT <- 1 - as.numeric(!is.na(study1_fu$Q97)) #CHANGE POLICY
study1_fu$CB_TREAT[!is.na(study1_fu$Q99)] <- 1 #CHANGE LAW
study1_fu$CB_TREAT[!is.na(study1_fu$Q101)] <- 2 #CHANGE CONSTITUTION
study1_fu$CB_TREAT[!is.na(study1_fu$Q103)] <- 3 #CHANGE CONSTITUTION + CERTAINTY
##################

####CREATE / RENAME VARIABLES####
study1_fu$MALE <- as.numeric(study1_fu$Q68.1 == 1)
study1_fu$AGE <- study1_fu$Q40_1
study1_fu$AGE[study1_fu$AGE==0] <- NA
study1_fu$AGE[study1_fu$AGE==220] <- 22
study1_fu$EDUCATION <- study1_fu$Q60
study1_fu$INCOME <- study1_fu$Q48.2
study1_fu$LIBCON <- study1_fu$Q52
study1_fu$RISK <- abs(11-study1_fu$Q77)
study1_fu$UNIONS <- study1_fu$Q41_3
study1_fu$TAXES <- study1_fu$Q84_1
study1_fu$WORKS <- abs(5 - study1_fu$Q7_1) + (study1_fu$Q7_2 - 1) + abs(5 - study1_fu$Q7_3) + (study1_fu$Q7_4 - 1) + (study1_fu$Q7_5 - 1)
study1_fu$BLACK <- as.numeric(study1_fu$Q56 == 2)
study1_fu$HISP <-  as.numeric(study1_fu$Q56 == 3)
study1_fu$WHITE <-  as.numeric(study1_fu$Q56 == 5)
########################
